//解析URL
let urlStr=location.href;
let id=urlStr.split("?")[1].split("=")[1];
let getData=new FormData();
getData.append("id",id);

let nameStr=my$("stuName");//名字
let sexArr=document.getElementsByName("sex");
let ageStr=my$("stuAge");//年龄
let eduStr=my$("stuEdu");//大学
let cityObj=my$("stuCity");//城市
let numStr=my$("stuNum");


ajax("student/get.php","POST",getData,showList);

my$("btn").onclick=function () {
    let sexStr=1;
    for(let i=0;i<sexArr.length;i++){
        if(sexArr[i].checked){
            sexStr=sexArr[i].value;
        }
    }
    // let parStr="id="+id+"&name="+nameStr+"&sex="+sexStr+"&age="+ageStr+"&edu="+eduStr+"&city="+cityStr+"&no="+numStr;
   let changeData=new FormData();
    changeData.append("id",id);
    changeData.append("name",nameStr.value);
    changeData.append("sex",sexStr);
    changeData.append("age",ageStr.value);
    changeData.append("edu",eduStr.value);
    changeData.append("city",cityObj.value);
    changeData.append("no",numStr.value);
    ajax("student/update.php","POST",changeData,function(){
        location.href="showStu.html";
    });

}

function showList(jsonObj) {
    let dataArr=jsonObj.data;

    nameStr.value=dataArr.name;
    for(let i=0;i<sexArr.length;i++){
        if(sexArr[i].value==dataArr.sex){
            sexArr[i].checked=true;
        }
    }
    ageStr.value=dataArr.age;
    eduStr.value=dataArr.edu;
    cityObj.value=dataArr.city;
    numStr.value=dataArr.no;
}
